{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "c3368b33",
   "metadata": {},
   "outputs": [],
   "source": [
    "import joblib #引入可以调用模型的库\n",
    "import pandas as pd\n",
    "from sklearn import metrics\n",
    "from sklearn.model_selection import train_test_split\n",
    "import xgboost as xgb\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.metrics import confusion_matrix\n",
    "import seaborn as sns\n",
    "from sklearn.metrics import confusion_matrix\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "4af229ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = joblib.load('xgboost.pkl') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "b7e0abd1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "5196ece2",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"./data_template.csv\")\n",
    "dataset_use = pd.read_csv(\"./data_template.csv\") #需要预测的测试集合的导入，更换文件就可以更换test_case了\n",
    "dtest=xgb.DMatrix(dataset_use) # 输入成为xgbDMatrix\n",
    "y_pred=model.predict(dtest) #输入模型进行验证预测\n",
    "y_use = pd.DataFrame(y_pred)+1 #y数值的预测并且返还标签\n",
    "y_use.columns = ['Label'] # \n",
    "\n",
    "last_result = pd.concat([dataset_use,y_use],axis=1)\n",
    "result_path = \"data_result.csv\"\n",
    "last_result.to_csv(result_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0e2d2afa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "602c9beb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>length</th>\n",
       "      <th>height</th>\n",
       "      <th>roughness_values</th>\n",
       "      <th>adhesion</th>\n",
       "      <th>Youngs_modulus</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4400</th>\n",
       "      <td>24.514</td>\n",
       "      <td>15.248</td>\n",
       "      <td>16.981</td>\n",
       "      <td>9.07</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      length  height   roughness_values adhesion    Youngs_modulus\n",
       "4400  24.514  15.248             16.981       9.07             0.2"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99da1d1a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3e943c0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "572ce60f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c54b30f1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc52fdc9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a2d02c1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48542d5f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26283bcd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f44c007",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "409d383f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e196a4f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8e8d3c2d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 4401 entries, 0 to 4400\n",
      "Data columns (total 6 columns):\n",
      " #   Column             Non-Null Count  Dtype  \n",
      "---  ------             --------------  -----  \n",
      " 0   label              4401 non-null   int64  \n",
      " 1   length             4401 non-null   float64\n",
      " 2   height             4401 non-null   float64\n",
      " 3    roughness_values  4401 non-null   float64\n",
      " 4   adhesion           4401 non-null   float64\n",
      " 5   Youngs_modulus     4401 non-null   float64\n",
      "dtypes: float64(5), int64(1)\n",
      "memory usage: 206.4 KB\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"./celldata_fine_tuning.csv\")\n",
    "\n",
    "data=df.iloc[:,1:]\n",
    "\n",
    "target=df.iloc[:,:-5]\n",
    "\n",
    "# ss = MinMaxScaler()\n",
    "\n",
    "# target = ss.fit_transform(target)\n",
    "\n",
    "df.info()\n",
    "train_x, test_x, train_y, test_y = train_test_split(data,target,test_size=0.1,random_state=7,shuffle = True)\n",
    "dtest=xgb.DMatrix(test_x)\n",
    "y_pred=model.predict(dtest)\n",
    "y_use = pd.DataFrame(y_pred)+1\n",
    "y_use\n",
    "dataset_use = pd.read_csv(\"./Test_cases.csv\") #需要预测的测试集合的导入，更换文件就可以更换test_case了\n",
    "dtest=xgb.DMatrix(dataset_use) # 输入成为xgbDMatrix\n",
    "y_pred=model.predict(dtest) #输入模型进行验证预测\n",
    "y_use = pd.DataFrame(y_pred)+1 #y数值的预测并且返还标签\n",
    "y_use.to_csv('predict_result_1.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "910591d1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
